#include "server/EmptyResponser.h"

#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/THttpServer.h>
#include "gen-cpp/ChatService.h"

namespace atp = apache::thrift::protocol;
namespace att = apache::thrift::transport;

namespace server {

EmptyResponser EmptyResponser::self_;

EmptyResponser& EmptyResponser::Instance() {
  return self_;
}
const std::string& EmptyResponser::GetResponse() const {
  return resp_;
}
EmptyResponser::EmptyResponser() {
  boost::shared_ptr<att::TMemoryBuffer> outTrans(new att::TMemoryBuffer());
  boost::shared_ptr<att::TTransport> trans(new att::THttpServer(outTrans));
  boost::shared_ptr<atp::TProtocol> prot(new atp::TBinaryProtocol(trans));
  trans->open();
  chat::ChatServiceClient client(prot);
  chat::SendEmptyResponseReq req;
  client.SendEmptyResponse(req);
  resp_ = outTrans->getBufferAsString();
}
}
